package Domain;

import Technical.Database;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;

public class BlogBean implements Serializable{
	private ArrayList<PostBean> posts = new ArrayList();
	private UserBean user = new UserBean();
	private String blogName;

	private int blogId;
		
	public BlogBean() {}
    
    public PostBean getLatestPost(){
        return posts.get(posts.size()-1);
    }
	public void setblogName(String blogName) {
		this.blogName = blogName;
	}
	public void setblogId(int blogId){
		this.blogId = blogId;
	}
	public String getblogName() {
		return blogName;
	}
	public int getblogId(){
		return blogId;
	}
    public void setuser(UserBean user){
        this.user = user;
    }
	public void addNewPost(PostBean post) {
		this.posts.add(post);
	}
		public Iterator getAllPosts(){
        return posts.iterator();
    }
    public UserBean getuser(){
        return user;
    }
	public void setPostsList(ArrayList list){
		this.posts = list;
	}
    public Boolean postExists(int postId){
        for(int i = 0; i < posts.size(); i++){
            if(postId == posts.get(i).getpostId())
                return true;
        }
        return false;
    }
    public PostBean getPost(int postId){
        PostBean post = new PostBean();
        for(int i = 0; i < posts.size(); i++){
            if(postId == posts.get(i).getpostId())
                post = posts.get(i);
        }
        return post;
    }
}
